{extend name="public:base" /}
{block name="style"}
<link rel="stylesheet" type="text/css" href="__INDEX__/css/public.css">
<link rel="stylesheet" type="text/css" href="__INDEX__/css/style.css">
<link rel="stylesheet" type="text/css" href="__INDEX__/css/responsive.css">
<link rel="shortcut icon" href="__INDEX__/images/favorite.ico">
{/block}

{block name="html"}
{include file="index@public/main" /}

<div class="right_style">
	<h3 class="title_style"><em></em><span>修改密码</span></h3>
	<div id="edit_passd">
		<div class="form">
			<form>
				<div class="group">
					<label for="tel">手机号</label>
					<input name="tel" id="phone" value="{$phone}" placeholder="手机号" disabled />
				</div>
				<div class="group">
					<label for="check">验证码</label>
					<input name="check" class="check" id="code" placeholder="验证码" />
					<input type="button" id="J_getCode" class="checkbtn" value="获取验证码" />
				</div>
				<div class="group">
					<label for="oldpasswd">新密码</label>
					<input type="password" name="pwd" id="oldpasswd" placeholder="输入新密码" />
				</div>
				<div class="group">
					<label for="newpassword">确认密码</label>
					<input type="password" name="pwd_a" id="newpassword" placeholder="重新输入密码" />
				</div>
				<input type="submit" id="submitReg" class="submit" value="确定" />
			</form>
		</div>
	</div>
</div>

{/block}
{block name="javascript"}

    <script src="__INDEX__/js/jquery-1.9.1.min.js"></script>
    <script src="__INDEX__/js/layer/mobile/layer_mobile.js"></script>
    <script src="__INDEX__/js/layer/mobile/layer.js"></script>
	<script>
        $("#submitReg").click(function(){
            var pwd = $("input[name='pwd']").val();
            var pwd_a = $("input[name='pwd_a']").val();
            var code = $("#code").val();
            if( pwd == "" || pwd != pwd_a ){
                layer_alert("二次登录密码不一至!");
                return false;
            }

            if(code.match(/^\d{6}$/) == null){
                layer_alert("请输入验证码");
                return false;
            }
            $.ajax({
                type: 'POST',
                url: '{:url("User/save_paw")}',
                dataType: 'json',
                data: {
                    pwd: pwd,
                    save_code:code
                },
                success: function (data) {
                    if( data.result == 0 ){
                        layer.open({
                            content: data.msg
                            ,style: 'color:#fff;background-color:#da7276; border:none;'
                            ,time: 2 //2秒后自动关闭
                            ,end:function(){
                                window.location.href='{:url("User/index")}';
                            }
                        });

                    }else{

                        layer_alert(data.msg);
                    }
                }
            });
            return false;
        });


	</script>

	<script>

		$("#J_getCode").click(function(){
	    var timer=null,num=60;
	    var phone= $('#phone').val();
	    if ("" == phone || !phone) {
            layer_alert("请输入手机号!");
	        return false;
	    } else {
	        var reg = /^0?1[3|4|5|7|8][0-9]\d{8}$/;
	        //验证规则
	        if (!reg.test(phone)) {
                layer_alert("手机号格式错误!");
	            return false;
	        }
	    }
	    $.ajax({
	        type: 'POST',
	        url: '{:url("User/save_code")}',
	        dataType: 'json',
	        data: {phone: phone},
	        success: function (data) {
	            if( data.result == 0 ){
                    layer_alert(data.msg);
	            }else{
                    layer_alert(data.msg);
	            }
	        }
    	});

	    timer = setInterval(function(){

		    $(".checkbtn").attr("disabled",true);
		    $(".checkbtn").val(num+"s"+"重新发送");
		    if(num < 0){
		        $(".checkbtn").val("获取验证码 ");
		        $(".checkbtn").removeAttr("disabled");
		        clearInterval(timer);
		    }
		    num--;
		},1000);

	})
        function layer_alert(src){
            layer.open({
                content: src
                ,style: 'color:#fff;background-color:#da7276; border:none;'
                ,time: 2 //2秒后自动关闭
            });
        }
	</script>
	{/block}
